﻿using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AES小工具
{
    public partial class FrmFloat : Form
    {
        public FrmFloat()
        {
            InitializeComponent();
        }

        private void FrmFloat_Load(object sender, EventArgs e)
        {
            ToolTip p = new ToolTip();
            p.IsBalloon = true;
            p.SetToolTip(this.tbName1, "名称");
            p.SetToolTip(this.tbName2, "名称");
            p.SetToolTip(this.tbName3, "名称");
            p.SetToolTip(this.tbName4, "名称");
            p.SetToolTip(this.tbName5, "名称");

            p.SetToolTip(this.tbCost1, "当前成本");
            p.SetToolTip(this.tbCost2, "当前成本");
            p.SetToolTip(this.tbCost3, "当前成本");
            p.SetToolTip(this.tbCost4, "当前成本");
            p.SetToolTip(this.tbCost5, "当前成本");

            p.SetToolTip(this.tbPrice1, "现在的价格");
            p.SetToolTip(this.tbPrice2, "现在的价格");
            p.SetToolTip(this.tbPrice3, "现在的价格");
            p.SetToolTip(this.tbPrice4, "现在的价格");
            p.SetToolTip(this.tbPrice5, "现在的价格");

            p.SetToolTip(this.tbInterval1, "计算间隔，1即以1%进行计算");
            p.SetToolTip(this.tbInterval2, "计算间隔，1即以1%进行计算");
            p.SetToolTip(this.tbInterval3, "计算间隔，1即以1%进行计算");
            p.SetToolTip(this.tbInterval4, "计算间隔，1即以1%进行计算");
            p.SetToolTip(this.tbInterval5, "计算间隔，1即以1%进行计算");

            p.SetToolTip(this.tbNum1, "以计算间隔进行计算生成的数值个数，上、下的值个数以这个值为准");
            p.SetToolTip(this.tbNum2, "以计算间隔进行计算生成的数值个数，上、下的值个数以这个值为准");
            p.SetToolTip(this.tbNum3, "以计算间隔进行计算生成的数值个数，上、下的值个数以这个值为准");
            p.SetToolTip(this.tbNum4, "以计算间隔进行计算生成的数值个数，上、下的值个数以这个值为准");
            p.SetToolTip(this.tbNum5, "以计算间隔进行计算生成的数值个数，上、下的值个数以这个值为准");

            p.SetToolTip(this.tbUp1, "以计算间隔进行计算的上行价格");
            p.SetToolTip(this.tbUp2, "以计算间隔进行计算的上行价格");
            p.SetToolTip(this.tbUp3, "以计算间隔进行计算的上行价格");
            p.SetToolTip(this.tbUp4, "以计算间隔进行计算的上行价格");
            p.SetToolTip(this.tbUp5, "以计算间隔进行计算的上行价格");

            p.SetToolTip(this.tbDown1, "以计算间隔进行计算的下行价格");
            p.SetToolTip(this.tbDown2, "以计算间隔进行计算的下行价格");
            p.SetToolTip(this.tbDown3, "以计算间隔进行计算的下行价格");
            p.SetToolTip(this.tbDown4, "以计算间隔进行计算的下行价格");
            p.SetToolTip(this.tbDown5, "以计算间隔进行计算的下行价格");

        }

        private void btnCreate1_Click(object sender, EventArgs e)
        {
            if(this.tbCost1.Text.IsNullOrEmpty() || this.tbPrice1.Text.IsNullOrEmpty() 
                || this.tbInterval1.Text.IsNullOrEmpty() || this.tbNum1.Text.IsNullOrEmpty()) 
                return;
            int num = int.Parse(this.tbNum1.Text);
            float interval = float.Parse(this.tbInterval1.Text)/100;
            float cost = float.Parse(this.tbCost1.Text);
            float price = float.Parse(this.tbPrice1.Text);
            string upStr = string.Empty;
            string downStr = string.Empty;

            for (int i = 1; i <= num; i++) { 
                if(!upStr.IsNullOrEmpty()) 
                    upStr += " , ";
                if (!downStr.IsNullOrEmpty()) 
                    downStr += " , ";
                upStr += (cost * (1 + interval * i)).ToString("0.000");
                downStr += (price * (1 - interval * i)).ToString("0.000");
            }
            this.tbUp1.Text = upStr;
            this.tbDown1.Text = downStr;
        }

        private void btnCreate2_Click(object sender, EventArgs e)
        {
            if (this.tbCost2.Text.IsNullOrEmpty() || this.tbPrice2.Text.IsNullOrEmpty()
                || this.tbInterval2.Text.IsNullOrEmpty() || this.tbNum2.Text.IsNullOrEmpty())
                return;
            int num = int.Parse(this.tbNum2.Text);
            float interval = float.Parse(this.tbInterval2.Text) / 100;
            float cost = float.Parse(this.tbCost2.Text);
            float price = float.Parse(this.tbPrice2.Text);
            string upStr = string.Empty;
            string downStr = string.Empty;

            for (int i = 1; i <= num; i++)
            {
                if (!upStr.IsNullOrEmpty())
                    upStr += " , ";
                if (!downStr.IsNullOrEmpty())
                    downStr += " , ";
                upStr += (cost * (1 + interval * i)).ToString("0.000");
                downStr += (price * (1 - interval * i)).ToString("0.000");
            }
            this.tbUp2.Text = upStr;
            this.tbDown2.Text = downStr;
        }

        private void btnCreate3_Click(object sender, EventArgs e)
        {
            if (this.tbCost3.Text.IsNullOrEmpty() || this.tbPrice3.Text.IsNullOrEmpty()
                || this.tbInterval3.Text.IsNullOrEmpty() || this.tbNum3.Text.IsNullOrEmpty())
                return;
            int num = int.Parse(this.tbNum3.Text);
            float interval = float.Parse(this.tbInterval3.Text) / 100;
            float cost = float.Parse(this.tbCost3.Text);
            float price = float.Parse(this.tbPrice3.Text);
            string upStr = string.Empty;
            string downStr = string.Empty;

            for (int i = 1; i <= num; i++)
            {
                if (!upStr.IsNullOrEmpty())
                    upStr += " , ";
                if (!downStr.IsNullOrEmpty())
                    downStr += " , ";
                upStr += (cost * (1 + interval * i)).ToString("0.000");
                downStr += (price * (1 - interval * i)).ToString("0.000");
            }
            this.tbUp3.Text = upStr;
            this.tbDown3.Text = downStr;
        }

        private void btnCreate4_Click(object sender, EventArgs e)
        {
            if (this.tbCost4.Text.IsNullOrEmpty() || this.tbPrice4.Text.IsNullOrEmpty()
                || this.tbInterval4.Text.IsNullOrEmpty() || this.tbNum4.Text.IsNullOrEmpty())
                return;
            int num = int.Parse(this.tbNum4.Text);
            float interval = float.Parse(this.tbInterval4.Text) / 100;
            float cost = float.Parse(this.tbCost4.Text);
            float price = float.Parse(this.tbPrice4.Text);
            string upStr = string.Empty;
            string downStr = string.Empty;

            for (int i = 1; i <= num; i++)
            {
                if (!upStr.IsNullOrEmpty())
                    upStr += " , ";
                if (!downStr.IsNullOrEmpty())
                    downStr += " , ";
                upStr += (cost * (1 + interval * i)).ToString("0.000");
                downStr += (price * (1 - interval * i)).ToString("0.000");
            }
            this.tbUp4.Text = upStr;
            this.tbDown4.Text = downStr;
        }

        private void btnCreate5_Click(object sender, EventArgs e)
        {
            if (this.tbCost5.Text.IsNullOrEmpty() || this.tbPrice5.Text.IsNullOrEmpty()
                || this.tbInterval5.Text.IsNullOrEmpty() || this.tbNum5.Text.IsNullOrEmpty())
                return;
            int num = int.Parse(this.tbNum5.Text);
            float interval = float.Parse(this.tbInterval5.Text) / 100;
            float cost = float.Parse(this.tbCost5.Text);
            float price = float.Parse(this.tbPrice5.Text);
            string upStr = string.Empty;
            string downStr = string.Empty;

            for (int i = 1; i <= num; i++)
            {
                if (!upStr.IsNullOrEmpty())
                    upStr += " , ";
                if (!downStr.IsNullOrEmpty())
                    downStr += " , ";
                upStr += (cost * (1 + interval * i)).ToString("0.000");
                downStr += (price * (1 - interval * i)).ToString("0.000");
            }
            this.tbUp5.Text = upStr;
            this.tbDown5.Text = downStr;
        }
    }
}
